<%@page import="实体类.PageInfo"%>
<%@page import="java.util.ArrayList"%>
<%@page import="实体类.Teacher"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="static/bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>

	<% 
	PageInfo pageInfo = (PageInfo)request.getAttribute("pageInfo");
	ArrayList<Teacher> list = (ArrayList<Teacher>)pageInfo.getList();
	%>
	<a type="button" href="<%=request.getContextPath() %>/teacher_insert.jsp" class="btn btn-success">添加</a>
	<table class="table table-striped table-bordered table-hover table-condensed">
	<tr>
		<th>id</th>
		<th>姓名</th>
		<th>年龄</th>
		<th>薪酬</th>
		<th>删除</th>
		<th>修改</th>
	</tr>
	<%for(Teacher teacher: list) {%>
		<tr>
			<td><%=teacher.getId() %></td>
			<td><%=teacher.getName() %></td>
			<td><%=teacher.getAge() %></td>
			<td><%=teacher.getSalary() %></td>
			<td><a href="javascript:deleteById(<%=teacher.getId() %>)">删除</a></td>
			<td><a href="<%=request.getContextPath() %>/teacher?method=selectById&id=<%=teacher.getId() %>">修改</a></td>
		</tr>
	<%} %>
	</table>
	<nav aria-label="Page navigation">
		  <ul class="pagination">
		  <% if(pageInfo.getPageNo() == 1){%>
		  		<li>
		      		<a aria-label="Previous">
		        		<span aria-hidden="true">&laquo;</span>
		     		 </a>
		    	</li>
		    <%} else {%>
		    <li>
		      <a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=pageInfo.getPageNo()-1%>" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
		    <%} %>
		    
		    <%
		    	for(int i = 1; i<= pageInfo.getTotalPage(); i++) {
		    		if (pageInfo.getPageNo() == i) {// 代表i当前的值就是当前页
		    %>
		    			<li><a><%=i%></a></li>
		    <%
		    		} else {
		    %>
		    			<li><a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=i%>"><%=i%></a></li>
		    <%
		    	    }
		    		
		    
		    	}
		    %>
		    
		   
		    <% if(pageInfo.getPageNo() == pageInfo.getTotalPage()){%>
		  		<li>
		      		<a aria-label="Previous">
		        		<span aria-hidden="true">&raquo;</span>
		     		 </a>
		    	</li>
		    <%} else {%>
		    <li>
		      <a href="<%=request.getContextPath()%>/teacher?method=selectByPage&pageNo=<%=pageInfo.getPageNo()+1%>" aria-label="Previous">
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
		    <%} %>
		  </ul>
		</nav>
	
	<script type="text/javascript">
		function deleteById(id){
			var isDelete = confirm("您确定要删除么？");
			if(isDelete){
				location.href = '<%=request.getContextPath() %>/teacher?method=deleteById&id=' + id;
			}
		}
	</script>
</body>
</html>